class Book
{
    constructor()
    {
        this.pageContainer = document.createElement("div");
        this.catalogContainer = document.createElement("div");
        this.pages = new Array();
        this.currentPage = 0;
        this.previousPage = 0;
        this.pageFactory = new SimplePageFactory();
    }

    setPageFactory(pageFactory)
    {
        this.pageFactory = pageFactory;   
    }

    mountMapBook(mapbook) {
        this.mapbook = mapbook;
        this.map = mapbook.map;
    }

    loadBook(bookContainer, bookConfig) {
        this.bookContainer = Select(bookContainer);
        this.bookConfig = bookConfig;
        this.bookConfig.pages.forEach((pageConfig) => {
            var page = this.pageFactory.newPage(this, pageConfig);
            this.addPage(page);
        });
        this.bookContainer.appendChild(this.pageContainer);
        this.pages[this.currentPage].setActived(true);
    }

    addPage(page, index)
    {
        var pageDiv = page.loadPage();
        pageDiv.dataset.pageNum = index;
        if (index == 0) {
            pageDiv.classList.add("book-pages-active");
        }
        this.pageContainer.appendChild(pageDiv);
        this.pages.push(page);
    }

    loadCatalog(catalogConfig) {

    }

    loadPagination() {

    }

    nextPage()
    {
        //下一页
    }

    lastPage()
    {
        //上一页
    }

    goto(pageNum)
    {
        //前往指定页面
    }

    onMapLoaded()
    {
        this.pages[this.currentPage].setActived(true);
    }
}
